#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;
int d[100005],v[100005],a[100005],p[100005],cnt[100005];
double tv[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    for(int kk=1;kk<=t;kk++){
        memset(cnt,0,sizeof(cnt));
        int n,m,l,V,ans1=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i];
        sort(p+1,p+m+1);
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                for(int k=1;k<=m;k++) cnt[k]++;
                if(v[i]>V) ans1++;
            }
            else{
                for(int j=1;j<=m;j++){
                    if(sqrt(v[i]*v[i]+2*a[i]*(p[j]-d[i]))>V&&d[i]<p[j]){
                        if(a[i]>0){
                            for(int k=j;k<=m;k++) cnt[k]++;
                        }
                        else if(a[i]<0){
                            for(int k=1;k<=j;k++) cnt[k]++;
                        }
                        ans1++;
                        j=m+1;
                    }
                    else{
                        for(int k=1;k<=m;k++) cnt[k]++;
                    }
                }
            }
        }
        int ans2=2;
        for(int i=1;i<=m;i++){
            if(cnt[i]==m){
                ans2=1;
                i=m+1;
            }
        }
        cout<<ans1<<" "<<n-ans2<<endl;
    }
    return 0;
}
